package mo.offer_special;

public class L068 {

    public int searchInsert(int[] nums, int target) {
        int left = 0;
        int right = nums.length - 1;
        while (left <= right) {
            int mid = left + (right - left) / 2;
            if (nums[mid] == target) {
                return mid;
            } else if (nums[mid] < target) {
                left = mid + 1;
            } else {
                right = mid -1;
            }
        }
        return right + 1;
    }

    public static void main(String[] args) {
        L068 test = new L068();
        System.out.println(test.searchInsert(new int[]{1, 3, 5, 6}, 0));
    }

}
